package com.may.wind.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * 权限信息
 */
@Entity
@Table(name = "permissions")
@JsonIgnoreProperties({"handler", "hibernateLazyInitializer"})
public class Permission implements Serializable {
    @Id
    @SequenceGenerator(sequenceName = "permission_sequence", name = "sequence_permissions", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence_permissions")
    @Column(name = "id")
    @ApiModelProperty(name = "id", value = "ID", required = true)
    private long id;

    /**
     * Permission name;
     */
    @ApiModelProperty(name = "name", value = "权限名称")
    private String name;

    /**
     * Permission's description(in Chinese)
     */
    @ApiModelProperty(name = "abs", value = "描述")
    private String abs;

    /**
     * The path which triggers permission check.
     */
    @ApiModelProperty(name = "url", value = "路径")
    private String url;

    /**
     * mapperBy为Role的permissions属性
     */
    @ManyToMany(mappedBy = "permissions", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    Set<Role> roles = new HashSet<>();

    public long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAbs() {
        return abs;
    }

    public void setAbs(String desc) {
        this.abs = desc;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}
